package com.cms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cms.dao.mapper.SystemRoleMapper;
import com.cms.exception.SystemDBException;
import com.cms.model.TrSysRole;
import com.cms.model.TrSysRoleFun;
import com.cms.service.SystemRoleService;

@Service
public class SystemRoleServiceImpl implements SystemRoleService{

	@Autowired
	private SystemRoleMapper roleMapper;
	
	@Override
	public void addSysRole(TrSysRole role) throws SystemDBException {
		roleMapper.addSysRole(role);
		List<TrSysRoleFun>funs= role.getFuns();
		if(funs!=null&&!funs.isEmpty())
		{
			this.roleMapper.addSysRoleFun(funs);
		}
		
	}

	@Override
	public void deleteSysRole(int roleId) throws SystemDBException {
		roleMapper.deleteSysRole(roleId);
		roleMapper.deleteRoleFun(roleId);
	}

	@Override
	public TrSysRole querySysRole(int roleId) throws SystemDBException {
		return roleMapper.querySysRole(roleId);
	}

	@Override
	public void updateSysRole(TrSysRole role) throws SystemDBException {
		    roleMapper.updateSysRole(role);
		    roleMapper.deleteRoleFun(role.getId());
			List<TrSysRoleFun>funs= role.getFuns();
			if(funs!=null&&!funs.isEmpty())
			{
				this.roleMapper.addSysRoleFun(funs);
			}
		  
	}

}
